package com.itheima.demo02;

import java.io.*;
import java.net.Socket;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/16 16:59
 */
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 12306);
        //创建输入流读取本地文件;
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("demo_TCP\\Client\\2019955.jpg"));
        //创建网络输出流把本地文件写出到服务器;
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());

        //进行读写操作;
        byte[] bytes = new byte[1024 * 8];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
            bos.flush();
        }
        socket.shutdownOutput();
        //接收服务器传过来的内容;
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        bis.close();
        socket.close();


    }
}
